package jdbcTest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcUtils {
	private static Connection connection = null;

	//获取连接
	public static Connection getConn() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection("jdbc:mysql:///test", "root", "1121");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return connection;
	}

	//释放连接
	public static void offconn(Connection connection) {
		if (connection != null) {
			try {
				connection.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	//释放St
	public static void stoff(Statement statement){
		if (statement != null) {
			try {
				statement.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	//释放结果集
	public static void reSetoff(ResultSet set){
		if (set!=null){
			try {
				set.close();
			}catch (Exception e){
				e.printStackTrace();
			}
		}
	}
}
